package com.zide.ams.service.impl;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.ams.domain.po.AmsTags;
import com.zide.ams.domain.vo.result.AmsTagsResultVO;
import com.zide.ams.domain.vo.save.AmsTagsSaveVO;
import com.zide.ams.domain.vo.search.AmsTagsSearchVO;
import com.zide.ams.mapper.AmsTagsMapper;
import com.zide.ams.service.IAmsTagsService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zide.common.core.vo.CommonParamIdVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 文章标签Service业务层处理
 * 
 * @author zide
 * @date 2024-04-29
 */
@Slf4j
@Service
public class AmsTagsServiceImpl implements IAmsTagsService {
    @Resource
    private AmsTagsMapper amsTagsMapper;

    /**
     * 查询文章标签列表
     */
    @Override
    public List<AmsTagsResultVO> searchAmsTagsList(AmsTagsSearchVO searchVO) {
        LambdaQueryWrapper<AmsTags> wrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotEmpty(searchVO.getName())) {
            wrapper.like(AmsTags::getName,searchVO.getName());
        }
        List<AmsTags> amsTags = amsTagsMapper.selectList(wrapper);
        return BeanUtil.copyToList(amsTags,AmsTagsResultVO.class);
    }

    /**
     * 查询文章标签详情
     */
    @Override
    public AmsTagsResultVO selectAmsTagsById(Long id) {
            AmsTags dbInfo = amsTagsMapper.selectById(id);
            AmsTagsResultVO result = BeanUtil.copyProperties(dbInfo,AmsTagsResultVO.class);
        return result;
    }

    /**
     * 新增文章标签
     */
    @Override
    public int saveAmsTags(AmsTagsSaveVO saveVO) {
        AmsTags insertBean = BeanUtil.copyProperties(saveVO,AmsTags.class);
        return amsTagsMapper.insert(insertBean);
    }

    /**
     * 修改文章标签
     */
    @Override
    public int updateAmsTags(AmsTagsSaveVO saveVO) {
        AmsTags updateBean = BeanUtil.copyProperties(saveVO,AmsTags.class);
        return amsTagsMapper.updateById(updateBean);
    }

    /**
     * 批量删除文章标签
     */
    @Override
    public int removeAmsTagsByIds(CommonParamIdVO idVO) {
        if(ArrayUtil.isNotEmpty(idVO.getIds())) {
            return amsTagsMapper.deleteBatchIds(Arrays.asList(idVO.getIds()));
        }else {
            return amsTagsMapper.deleteById(idVO.getId());
        }

    }

    @Override
    public int updateStatus(AmsTagsSaveVO saveVO) {
        AmsTags updateBean = BeanUtil.copyProperties(saveVO,AmsTags.class);
        return amsTagsMapper.updateById(updateBean);
    }
}
